import identity from './identity'
import isObject from '../object/isObject'
import matcher from '../object/matcher'
import isFunction from './isFunction'
import property from '../object/property'
import optimizeCallback from './optimizeCallback'

/**
 * 生成回调函数
 * @param {*} value
 * @param {*} context
 * @param {*} argCounts
 * @returns {Function}
 */
function callback(value, context, argCounts) {
  if (value == null) {
    return identity
  }
  if (isObject(value)) {
    return matcher(value)
  }
  if (isFunction(value)) {
    return optimizeCallback(value, context, argCounts)
  }
  return property(value)
}

export default callback
